package com.ruoyi.web.controller.system;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.service.ISysAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.ruoyi.common.core.domain.AjaxResult.success;

/**
 * 行政区表
 *
 * @author Ai
 */
@RestController
@RequestMapping("/system/area")
public class SysAreaController {
    @Autowired
    private ISysAreaService areaService;

    /**
     * 根据行政区名称获取行政区编码
     */
    @GetMapping(value="/{areaName}")
    public AjaxResult getAreaId(@PathVariable String areaName)
    {
        return success(areaService.selectAreaIdByAreaName(areaName));
    }

    /**
     * 根据行政区名称获取上级行政区编码
     */
    @GetMapping(value = "/getParent/{areaName}")
    public AjaxResult getParentAreaId(@PathVariable String areaName){
    return success(areaService.selectParentAreaIdByAreaName(areaName));
    }

    /**
     * 根据行政区编码获取行政区名称
     */
    @GetMapping(value = "/getName/{areaId}")
    public AjaxResult getAreaName(@PathVariable Long areaId){
        return success(areaService.selectAreaNameByAreaId(areaId));
    }
}
